import java.util.*;

public class HJ45 {
    public static void main(String[] args) {
        /**
         * 计算漂亮度
         * 按照字母出现的次数多少，越多分值越高，次数相同则按照字母表顺序排序
         */
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        while (sc.hasNext()){
            for (int i = 0; i < number; i++) {
                int beautiful = 0;
                String name = sc.next();
                String lowerName = name.toLowerCase();
                int[] s = new int[128];
                for (int j = 0; j < lowerName.length(); j++) {
                    s[lowerName.charAt(j)]++;
                }
                Arrays.sort(s);
                int temp = 26;
                for (int k = s.length-1; k >= 0 && s[k]>0 ; k--) {
                    beautiful = temp*s[k]+beautiful;
                    temp--;
                }
                System.out.println(beautiful);
            }
        }

    }


}
